<?php
	class VideoAction extends HomeAction{

		//内容页
		public function show(){
	        $this->header();    //导入页头
			$video=M('Video');
			$videoAttach=M('VideoAttach');
			$videourl=M('Videourl');
			
			$res1=$video->where(array('id'=>$_GET['id']))->find();	//打开主表
			$res2=$videoAttach->where(array('vid'=>$_GET['id']))->find();	//打开副表
			$videos=$videourl->where(array('vid'=>$_GET['id']))->getField('videoid,vtype');	//打开视频库,只获得视频类型

			if(empty($res1)){
				$this->error('您访问的页面不存在','',1);
			}

			$res=array_merge($res1,$res2);
			//打开当前ID视频库

			//整理数据
			$res['pic']=$this->litimg($res['pic']);	//缩略图
			$res['seotitle']=$res['seotitle']?$res['seotitle']:$res['title'];	//文章TITLE
			$res['content']=stripslashes($res['content']);
			
			$res['typename']=$this->typename($res['typeid']);//栏目名

			//按视频类型输出播放按钮
			$videotype=new VideoModel;
			$html=$videotype->html($videos);
			$this->assign('keywords',$res['keywords']);
			$this->assign('description',$res['description']);
			$this->assign('seotitle',$res['seotitle']);
			$this->assign('html',$html);
			$this->assign('list',$res);
			
			$this->display();
		}

		//视频播放页
		public function play(){
	        $this->header();    //导入页头
			$video=M('Video');
			$videoattach=M('VideoAttach');
			$videourl=M('Videourl');
			$videotype=M('Videotype');

			//输出视频标题
			$res=$video->where(array('id'=>$_GET['id']))->field('seotitle,id')->find();
			$res1=$videoattach->where(array('vid'=>$res['id']))->field('keywords,description')->find();
			$this->assign('keywords',$res1['keywords']);
			$this->assign('description',$res1['description']);
			$this->assign('seotitle',$res['seotitle']);

			//获得视频集
			$where['vid']=$_GET['id'];
			$where['vtype']=$_GET['type'];
			$urls=$videourl->where($where)->getField('vurl,vname');

			//将视频集按照名称进行重新排序
			natsort($urls);
			$i=0;
			foreach($urls as $k=>$v){
				$url[$i]['vname']=$v;
				$url[$i]['vurl']=$k;
				$i++;

			}

			//输出视频集数链接
			if($_GET['type']!='x'){
				$n=count($url);
				for($i=0;$i<$n;$i++){
					$videolinks.='<li><a href="'.__URL__.'/play/type/'.$_GET['type'].'/id/'.$_GET['id'].'/k/'.$i.'">'.$url[$i]['vname'].'</a></li>';
				}
			}else{
				$n=count($url);
				for($i=0;$i<$n;$i++){
					$videolinks.='<li><a href="'.$url[$i]['vurl'].'">'.$url[$i]['vname'].'下载</a></li>';
				}				
			}

			$this->assign('videolinks',$videolinks);

			//输出播放器代码
			$k=$_GET['k']?$_GET['k']:0;
			$videotype=$videotype->where(array('value'=>$_GET['type']))->find();
			$playhtml=str_replace('+UU+',$url[$k]['vurl'], $videotype['html']);
			$playhtml=str_replace('+WW+',$videotype['width'],$playhtml);
			$playhtml=str_replace('+HH+',$videotype['height'],$playhtml);
			$playhtml=stripslashes($playhtml);

			if($_GET['type']!='x'){
				$playhtml=$playhtml.'<div id="playd"><div id="onpl"><a href="#">我要评论</a></div><div id="ondp"><a href="#">发表点评</a></div></div>';
			}
			$this->assign('playhtml',$playhtml);

			//按视频类型输出播放按钮
			$videos=$videourl->where(array('vid'=>$_GET['id']))->getField('videoid,vtype');	
			$videotype=new VideoModel;
			$html=$videotype->html($videos);
			$this->assign('html',$html);

			$this->display();
		}




	}